/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.webcrm.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Frederiko
 */
@Entity
@Table(name = "ceps")
@NamedQueries({
    @NamedQuery(name = "Cep.findAll", query = "SELECT c FROM Cep c"),
    @NamedQuery(name = "Cep.findByIdcep", query = "SELECT c FROM Cep c WHERE c.idcep = :idcep"),
    @NamedQuery(name = "Cep.findByLogradouro", query = "SELECT c FROM Cep c WHERE c.logradouro = :logradouro"),
    @NamedQuery(name = "Cep.findByBairro", query = "SELECT c FROM Cep c WHERE c.bairro = :bairro")})
public class Cep implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "idcep", nullable = false)
    private Integer idcep;
    @Column(name = "logradouro", length = 70)
    private String logradouro;
    @Column(name = "bairro", length = 60)
    private String bairro;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cep", fetch = FetchType.LAZY)
    private List<Endereco> listaEnderecos;
    @JoinColumn(name = "idcidade", referencedColumnName = "idcidade", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Cidade cidade;

    public Cep() {
    }

    public Cep(Integer idcep) {
        this.idcep = idcep;
    }

    public Integer getIdcep() {
        return idcep;
    }

    public void setIdcep(Integer idcep) {
        this.idcep = idcep;
    }

    public String getLogradouro() {
        return logradouro;
    }

    public void setLogradouro(String logradouro) {
        this.logradouro = logradouro;
    }

    public String getBairro() {
        return bairro;
    }

    public void setBairro(String bairro) {
        this.bairro = bairro;
    }

    public List<Endereco> getListaEnderecos() {
        return listaEnderecos;
    }

    public void setListaEnderecos(List<Endereco> listaEnderecos) {
        this.listaEnderecos = listaEnderecos;
    }

    public Cidade getCidade() {
        return cidade;
    }

    public void setCidade(Cidade cidade) {
        this.cidade = cidade;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idcep != null ? idcep.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cep)) {
            return false;
        }
        Cep other = (Cep) object;
        if ((this.idcep == null && other.idcep != null) || (this.idcep != null && !this.idcep.equals(other.idcep))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.attende.model.Cep[idcep=" + idcep + "]";
    }

}
